package com.calvin.grpc.grpcserver.service.impl;

import com.geek.grpc.lib.hello.HelloRequest;
import com.geek.grpc.lib.hello.HelloResponse;
import com.geek.grpc.lib.hello.HelloServiceGrpc;
import io.grpc.stub.StreamObserver;
import net.devh.springboot.autoconfigure.grpc.server.GrpcService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * <p> </p>
 *
 * @author Calvin
 * @date 2019/09/17
 * @since
 */
@GrpcService(HelloServiceImpl.class)
public class HelloServiceImpl extends HelloServiceGrpc.HelloServiceImplBase {


    private static final Logger LOG = LoggerFactory.getLogger(HelloServiceImpl.class);

    @Override
    public void sayHello(HelloRequest request, StreamObserver<HelloResponse> responseObserver) {
        String name = request.getName();
        LOG.info("received client name is " + name);
        HelloResponse response = HelloResponse.newBuilder().setCode("0000").setMessage("hello "+ name).build();
        responseObserver.onNext(response);
        responseObserver.onCompleted();
    }
}
